// 通用组件的配置
import type { FormComponentType, FormItemType } from "./type";
import { useUserStore } from '@/Stores/user';

// 集团选择列表组件
export const blockListConfig: FormComponentType = {
    type: 'select',
    placeholder: '选择集团',
    api: {
        url: '/user/bloc-info/adminGetUserBlocs',
        method: 'post',
        query: async () => {
            return {
                id: (await useUserStore().getUserInfo()).id
            }
        }
    },
    selectProps: {
        label: 'blocName',
        key: 'id'
    }
}

// 平台列表组件通用配置
export const platformListConfig: FormComponentType = {
    type: 'select',
    placeholder: '选择平台',
    api: {
        url: '/dms/shop/indicator/adminPlatform',
        method: 'get',
        query: async () => {
            return {
                userId: (await useUserStore().getUserInfo()).id
            }
        }
    },
    selectProps: {
        label: 'name',
        key: 'id'
    }
}

// 平台列表通用配置，表单组件
export const platformItemListConfig: FormItemType = {
    key: 'platformId',
    label: '平台',
    ...platformListConfig
}

// 店铺选择组件通用配置
export const shopListConfig: FormComponentType = {
    type: 'select',
    dependencies: {
        key: 'platformId',
        requestKey: 'platform',
        required: true
    },
    api: {
        url: '/dms/shop/indicator/adminGetShopList',
        method: 'get',
        query: async () => {
            return {
                isAccount: false,
                isShare: true,
                userId: (await useUserStore().getUserInfo()).id,
            };
        }
    },
    selectProps: {
        label: 'shopName',
        key: 'id'
    }
}

// 店铺选择组件通用配置，表单组件
export const shopFormItemListConfig: FormItemType = {
    key: 'shopIds',
    type: 'select',
    label: '店铺',
    ...shopListConfig
}

// 店铺子账号选择组件
export const accountShopListConfig: FormComponentType = {
    type: 'select',
    dependencies: {
        key: 'shopId',
        requestKey: 'shopId',
        required: true
    },
    api: {
        url: '/user/public/adminFindAllAccount',
        method: 'get',
        query: async () => {
            return {
                userId: (await useUserStore().getUserInfo()).id,
            };
        }
    },
    selectProps: {
        label: 'account',
        key: 'id'
    }
}

// 店铺子账号选择组件，表单组件
export const accountShopFormItemListConfig: FormItemType = {
    key: 'accountId',
    label: '子账号',
    ...accountShopListConfig,
}

// 组织树选择组件
export const orgTreeConfig: FormComponentType = {
    type: 'treeSelect',
    placeholder: '请选择组织',
    api: {
        url: '/user/public/adminGetUserTree',
        method: 'get',
        query: async () => {
            return {
                id: (await useUserStore().getUserInfo()).id
            }
        }
    },
    multiple: true,
    selectProps: {
        label: 'name',
        key: 'id'
    }
}

// 组织树选择组件，表单组件
export const orgFormItemListConfig: FormItemType = {
    key: 'infoAccountUserIds',
    label: '组织',
    ...accountShopListConfig,
}